package com.bxd.baodan.activity;

import android.view.View;

import com.google.gson.reflect.TypeToken;
import com.bxd.baodan.App;
import com.bxd.baodan.R;
import com.bxd.baodan.app.JsonApi;
import com.bxd.baodan.item.DesignReportBean.DataBean.ReportBean_;
import com.bxd.baodan.util.NetUtil;
import com.umeng.analytics.MobclickAgent;
import com.bxd.baodan.adapter.ViewHolder;

import java.lang.reflect.Type;
import java.util.List;

public class ReportActivity extends BaseListActivity<ReportBean_> {
    @Override
    protected int getActivityLayout() {
        return R.layout.pull_refresh_layout_no_divider;
    }

    @Override
    protected void preDone() {
        setActionBarTitle("方案报告");
        footer = View.inflate(this, R.layout.report_null_footer, null);
        autoRefresh();
    }

    @Override
    protected Type getTypeToken() {
        return new TypeToken<List<ReportBean_>>() {
        }.getType();
    }

    @Override
    protected int getItemLayout() {
        return R.layout.report_item_layout;
    }

    @Override
    protected void setNetUtil() {
        netUtil = new NetUtil(this, JsonApi.DESIGN_LISTS);

    }

    @Override
    protected void convert(ViewHolder holder, final ReportBean_ item) {
        holder.setText(R.id.title, "的"+item.title);
        holder.setText(R.id.name, item.name);
        holder.setText(R.id.date,item.date);
        holder.getView(R.id.see).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // TODO: 17/9/7  有问题
                MobclickAgent.onEvent(App.getContext(), "v6_1_3_WD_fabg_bgxq");
                openActivity(WebViewPager.class, new String[]{"startUrl"}, new String[]{item.url});

            }


        });

        holder.getView(R.id.del).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NetUtil netUtil = new NetUtil(ReportActivity.this, JsonApi.DESIGN_DELETE);
                netUtil.setParams("reportId", item.id);

                netUtil.postRequest("", new NetUtil.RequestStringListener() {
                    @Override
                    public void onComplete(String result) {
                        showToast("删除成功");
                        autoRefresh();

                    }
                });

            }


        });
    }

    @Override
    protected String getArrayStr(String json_data) {
        return "list";
    }

}
